package com.example.saiaadmin.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.saiaadmin.common.GetCunrrentUser;
import com.example.saiaadmin.entry.EbSystemLoginLog;
import com.example.saiaadmin.entry.EbSystemOperLog;
import com.example.saiaadmin.entry.EbSystemUser;
import com.example.saiaadmin.service.EbSystemOperLogService;
import com.example.saiaadmin.utils.PageBean;
import com.example.saiaadmin.utils.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * 操作日志表Controller
 *
 *  @author  Vagrant
 * @since 2025/01/13
 */
@RestController
@RequestMapping("/eb-system-oper-log")
public class EbSystemOperLogController {

    @Autowired
    private EbSystemOperLogService service;
    /**
     * 获取登录日志列表
     * @return
     */
    @GetMapping("/获取操作日志列表")
    public ResultData<PageBean<EbSystemOperLog>> getLoginLogList(Integer pageNum, Integer pageSize){
        if(null ==pageNum){
            pageNum=1;
        }
        if(null ==pageSize){
            pageSize=5;
        }
        Page<EbSystemOperLog> pageinfo = new Page<>(pageNum,pageSize);
        GetCunrrentUser getCunrrentUser = new GetCunrrentUser();
        EbSystemUser systemUser=getCunrrentUser.getUser();
        LambdaQueryWrapper<EbSystemOperLog> loginLogWrapper= new LambdaQueryWrapper<>();
        loginLogWrapper.eq(EbSystemOperLog::getUsername,systemUser.getUsername());
        loginLogWrapper.orderByDesc(EbSystemOperLog::getCreateTime);
        service.page(pageinfo,loginLogWrapper);

        PageBean<EbSystemOperLog> pageBean =new PageBean<>();
        pageBean.setTotal(pageinfo.getTotal());
        pageBean.setData(pageinfo.getRecords());
        pageBean.setPer_page((int) pageinfo.getSize());
        pageBean.setLast_page((int) pageinfo.getPages());
        return ResultData.success("查询成功",pageBean);
    }
}
